package ru.aslanov.schedule.client.util;

import com.smartgwt.client.util.SC;
import ru.aslanov.schedule.client.i18n.I18nUtil;

/**
 * Created by IntelliJ IDEA.
 * Created: Mar 9, 2010 1:50:25 PM
 *
 * @author Sergey Aslanov
 */
public class ErrorHandler {
    public static void handleException(Throwable t) {
        operationFailed(t.toString());
    }

    public static void operationFailed(String message) {
        final int MAX_LEN = 250;
        if (message != null && message.length() > MAX_LEN) {
            message = message.substring(0, message.indexOf(' ', MAX_LEN - 50));
            if (message.length() > MAX_LEN) {
                message = message.substring(0, MAX_LEN);
            }
            message += "...";
        }
        SC.warn(I18nUtil.cnt().operationError() + (message != null ? ("<br/>" + message) : ""));
    }
}
